﻿#include "stdafx.h"
#include "videocapture.h"
#include "..\..\lib\10moons\Inc\DSStream.h"

CVideoCapture::CVideoCapture()
{
    m_pCapture = NULL;
    m_pFrame = NULL;
}


CVideoCapture::CVideoCapture(const char* filename)
{
    if (filename == NULL)
    {
        return;
    }
    m_pCapture = NULL;
    m_pFrame = NULL;
    this->filename = filename;

    InitCapture();
}


CVideoCapture::~CVideoCapture()
{
    if (m_pCapture != NULL)
    {
        cvReleaseCapture(&m_pCapture);
    }
}


void CVideoCapture::SetFileName(const char* filename)
{
    this->filename = filename;

    InitCapture();
}

int CVideoCapture::InitCapture()
{
    
    return 0;
}

IplImage* CVideoCapture::CaptureFrame()
{
    BOOL isLocked = false;
    HRESULT r = S_FALSE;
    r = DSStream_IsVideoSignalLocked(this->cardNo, &isLocked);
    if (FAILED(r))
    {
        cout<<"获取图片失败"<<endl;
        return NULL;
    }

    if (!isLocked)
    {
        return NULL;
    }

    char *fileName = "temp.jpg";

    r = DSStream_SaveToJpgFile(this->cardNo, fileName, 75);
    if (FAILED(r))
    {
        cout<<"保存图片失败"<<endl;
    }
    Sleep(50);

    return cvLoadImage(fileName, 1);
}


